package com.yehongyu.mytools.ui.applet;

//: CardLayout1.java
//Demonstrating the CardLayout
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class CardLayoutExample extends Applet {
	/**序列ID*/
	private static final long serialVersionUID = 1L;

	Panel cards = new Panel();
	CardLayout cl = new CardLayout();

	public void init() {
		setLayout(new BorderLayout());	//设置整体边框布局
		//设置按钮面板
		Panel p = new Panel();
		Button first = new Button("First"), second = new Button("Second"), third = new Button("Third");
		p.setLayout(new FlowLayout());	//设置流布局
		p.add(first);
		p.add(second);
		p.add(third);
		add("North", p);
		first.addActionListener(new B1Action());
		second.addActionListener(new B2Action());
		third.addActionListener(new B3Action());
		
		cards.setLayout(cl);	//设置卡片布局
		cards.add("First card", new ButtonPanel("The first one"));
		cards.add("Second card", new ButtonPanel("The second one"));
		cards.add("Third card", new ButtonPanel("The third one"));
		add("Center", cards);
	}

	private class B1Action implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			cl.first(cards);
		}
	}

	private class B2Action implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			cl.first(cards);
			cl.next(cards);
		}
	}

	private class B3Action implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			cl.last(cards);
		}
	}
	
	private class ButtonPanel extends Panel {
		/**序列ID*/
		private static final long serialVersionUID = 1L;
		ButtonPanel(String id) {
			setLayout(new BorderLayout());
			add("Center", new Button(id));
		}
	}

}
